﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Lister;
using System.Threading;

namespace COFE.Core.Tasks
{
    public class EntryListActionProvider : ISecondaryPropertyProvider
    {
        #region Constructor

        #endregion

        #region Methods

        public object[] GetSupportedProperty(IFileSystemInfo sourceObj)
        {
            if (sourceObj is IEntryList)
            {
                return new object[] {
                    EntryListActions.List
                };
            }

            return new object[] { };
        }

        public bool IsPropertyReadOnly(IFileSystemInfo sourceObj, object property)
        {
            return true;
        }


        IEntryList List(IEntryList input, string param)
        {            
            IAutoEntryList retVal = new AutoEntryList("", param);
            var etor = retVal.Entries.GetEnumerator();

            var counter = 0;
            while (!COFETaskShared.CancellationToken.IsCancellationRequested && etor.MoveNext())
                COFETaskShared.TaskProgressDispatcher.DispatchEvent(this, new TaskProgressEventArgs(-1, ++counter));

            if (COFETaskShared.CancellationToken.IsCancellationRequested)
                COFETaskShared.CancellationToken.ThrowIfCancellationRequested();

            if (retVal.Error != null)
                throw new Exception(retVal.Error.Message, retVal.Error);                   

            
                return retVal;           
        }

        public IO.PropertyPair GetProperty(IFileSystemInfo sourceObj, object property)
        {
            throw new NotImplementedException();
        }

        public void SetProperty(IFileSystemInfo sourceObj, object property, object value)
        {
           
        }

        #endregion

        #region Data

        #endregion

        #region Public Properties

        #endregion
    }
}
